home *** CD-ROM | disk | FTP | other *** search
- /*
- FILENAME
- ChooserPACK.c
-
- DESCRIPTION
- Contains code for PACK resource used by the Chooser.
-
- COPYRIGHT
- Copyright © 1995 Apple Computer, Inc.
- All rights reserved.
-
- Modification history
- 10/04/95 - David Hayward - Version 1.0.4 modified code so that
- the driver can be build under MPW,
- Metrowerks, and Symantec. In general,
- all that was required to do this was
- to add an inline-assembly jumptable
- and to store all globals off of the
- message manager instance context.
- Also made a few changes so that the
- driver can be rebuilt to support any
- resolution by changing the #defines
- kResolution and kPatStretch in
- "CommonDefines.h"
-
- 06/14/95 - Dave Hersey - Version 1.0.3 to fix a bug in
- CustomBufferingAndIO.c when creating
- high-res PICTs, and to make the size
- of buffers more flexible.
-
- 05/26/95 - Dave Hersey - Version 1.0.2 to add the new 'outp'
- desktop printer resource in NewApp.c.
-
- 05/03/95 - Dave Hersey - Version 1.0.1 to fix some minor bugs in
- CustomBufferingAndIO.c.
-
- 01/14/95 - Dave Hersey - Created from the shell of a hollowed-out
- ImageWriter driver.
-
- NOTE: Relevant goodies are listed in MPW's "Mark" menu.
- */
-
-
- #include <Types.h>
- #include <Traps.h>
- #include <Resources.h>
- #include <GXGraphics.h>
- #include <GXTypes.h>
- #include <GXPrinterDrivers.h>
- #include <GXPrinting.h>
- #include <Devices.h>
-
-
- // typedef for structure to hold globals for PACK code.
- typedef struct PACKglobal
- {
- gxJob job;
- Str31 driverName;
- } PACKglobalRec, *PACKglobalPtr;
-
-
- // Prototype for main function.
- pascal OSErr PACKmain ( short message, short caller,
- StringPtr objName, StringPtr zoneName,
- ListHandle theList, long p2,
- PACKglobalPtr global) ;
-
-
- /* -----------------------------------------------------------------------
-
- __Startup__ contains our jump table to the overrides.
- This code must be kept in sync with the assembly code
- in ChooserPACK.a
-
- ----------------------------------------------------------------------- */
-
- #if defined(__MWERKS__)
-
- #define kLeftButton 0x08000000
- #define kUsesOnAndOff 0x00100000
- #define kAcceptsInit 0x00020000
- #define kAcceptsTerminate 0x00000800
-
- asm void __Startup__(void) ;
- asm void __Startup__(void)
- {
- BRA.S code // branch to our actual code
- DC.W 169 // device ID
- DC.L 'PACK' // device type
- DC.W 0xF000 // master ID for resources (-4096)
- DC.W 2 // version
- DC.L kLeftButton+kUsesOnAndOff+kAcceptsInit+kAcceptsTerminate
-
- data:
- ds.b sizeof(PACKglobalRec)
-
- code:
- MOVE.L (a7)+,a0 // move return address into a0
- PEA data // add a pointer to our global data onto stack as last parameter
- MOVE.L a0,-(a7) // put the return address back on the stack
- jmp PACKmain // jump to it, so when it does the return, it goes to OUR caller
- rts
- }
- #endif
-
-
- pascal OSErr PACKmain ( short message, short caller,
- StringPtr objName, StringPtr zoneName,
- ListHandle theList, long p2,
- PACKglobalPtr global)
- {
- OSErr anErr = noErr;
-
- // start up GX.
- if (message == chooserInitMsg)
- {
- FCBPBRec pb;
-
- // determine the driver name
- pb.ioCompletion = nil;
- pb.ioNamePtr = global->driverName;
- pb.ioVRefNum = 0;
- pb.ioRefNum = CurResFile();
- pb.ioFCBIndx = 0;
- anErr = PBGetFCBInfo(&pb, false);
-
- global->job = nil;
- if (anErr == noErr)
- {
- GXEnterGraphics();
- anErr = GXGetGraphicsError(nil);
- if (anErr == noErr)
- {
- anErr = GXInitPrinting();
- if (anErr != noErr)
- GXExitGraphics();
- }
- }
- }
-
- // Let the system handle the choosing for us.
- if (anErr == noErr)
- {
- if ((global->job != nil) || (message == chooserInitMsg))
- {
- anErr = GXHandleChooserMessage( &(global->job),
- global->driverName,
- message, caller, objName, zoneName, theList, p2);
-
- // Tear down GX when done.
- if ((message == terminateMsg) && (p2 == terminateMsg))
- {
- GXExitPrinting();
- GXExitGraphics();
- }
- }
- }
-
- return anErr;
-
- }
-